/*
 * @Author: 郑刘利
 * @Date: 2020-03-17 22:33:28
 * @LastEditors: 郑刘利
 * @LastEditTime: 2020-03-18 00:54:36
 * @Description: file content
 * @FilePath: \one_project\src\core\domain\social\Signal.ts
 */
import { IUser } from '../user/User';
import { Echo } from './Echo';

export enum SignalType {
    'photo-text' = 1, // 图文
    'voice' = 2, // 有声
    'sample' = 3, // 采样
    'ad' = 4 // 广告
}
export interface ISignal extends UCC<IUser> {
    type: SignalType;
    echo?: Echo;
}
export abstract class Signal<T> implements ISignal {
    public static getInstance(base: ISignal, payload: IPayload<any>) {
        switch (base.type) {
            case SignalType['photo-text']:
                return new PhotoTextSignal(base, payload);
            case SignalType.voice:
                return new VoiceSignal(base, payload);
            case SignalType.sample:
                return new SampleSignal(base, payload);
            default:
                return null;
        }
    }

    public id: string;
    public form: IUser;
    public type: SignalType;
    public echo?: Echo;
    public payload: IPayload<T>;

    protected constructor(base: ISignal, payload: IPayload<T>) {
        this.id = base.id;
        this.form = base.form;
        this.type = base.type;
        this.echo = base.echo;
        this.payload = payload;
    }
}
export interface IPayload<T> {
    content: T;
}

export enum PhotoTextPayloadContentType {
    'photo' = 0,
    'text'
}
export interface PhotoContent {
    type: 0;
    src: string;
}
export interface TextContent {
    type: 1;
    text: string;
}
export type PhotoTextPayloadType = PhotoContent | TextContent[];
export class PhotoTextSignal extends Signal<PhotoTextPayloadType> {}

export type VoicePayloadType = string[];
export class VoiceSignal extends Signal<VoicePayloadType> {}

export type SamplePayloadType = string[];
export class SampleSignal extends Signal<SamplePayloadType> {}
